package com.dinggou.shopjb.adapters;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.dinggou.shopjb.R;
import com.dinggou.shopjb.base.BaseRVAdapter;
import com.dinggou.shopjb.base.BaseRVHolder;
import com.dinggou.shopjb.bean.SellOrderInfoBean;
import com.zc.mychart.utils.FormatUtil;

import java.util.List;

public class CattleBillAdapter extends BaseRVAdapter {
    public CattleBillAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public int onCreateViewLayoutID(int viewType) {
        return R.layout.item_cattle_bill;
    }

    @Override
    public void onBindView(BaseRVHolder holder, int position) {
        SellOrderInfoBean bean = (SellOrderInfoBean)mList.get(position);
        TextView buy_type_tv = holder.getViewHolder().get(R.id.buy_type_tv);
        TextView time_tv  =  holder.getViewHolder().get(R.id.time_tv);
        TextView buy_amount =  holder.getViewHolder().get(R.id.buy_amount);
        ImageView icon = holder.getViewHolder().get(R.id.user_icon);
        TextView user_name_time =holder.getViewHolder().get(R.id.user_name_time);
        TextView add_number = holder.getViewHolder().get(R.id.add_number);
        TextView lv_tv = holder.getViewHolder().get(R.id.lv_tv);
        TextView pro_name_tv = holder.getViewHolder().get(R.id.pro_name_tv);
        if (bean.trade_type == 1) {
            int greenColor = ContextCompat.getColor(mContext, R.color.buy_green);
            buy_type_tv.setText("结算价订购");
            buy_type_tv.setTextColor(greenColor);
            buy_type_tv.setBackgroundResource(R.drawable.shape_rect_round_2dp_daf2e4);

        } else {
            int redColor = ContextCompat.getColor(mContext, R.color.buy_red);
            buy_type_tv.setText("现价订购");
            buy_type_tv.setTextColor(redColor);
            buy_type_tv.setBackgroundResource(R.drawable.shape_rect_round_2dp_ffe7e7);
        }
        String describe = "用时" + FormatUtil.dateToStamp(bean.build_time_unix, bean.liqui_time_unix);
        time_tv.setText(describe);
        buy_amount.setText(bean.unit_price+"元x"+bean.amount+"件");
        Glide.with(mContext).load(bean.header_img).into(icon);
        user_name_time.setText(bean.nick_name+" | "+FormatUtil.getDataMDHMFromTimestamp(Long.valueOf(bean.build_time_unix)));
        add_number.setText(bean.pro_loss+"元");

        int lv = (int)((bean.pro_loss/(bean.unit_price*bean.amount))*100);
        lv_tv.setText("增益率"+lv+"%");
        pro_name_tv.setText(bean.pro_name);
    }
}
